package com.wt.admin.controller.language;


import com.aizuda.easy.security.domain.Rep;
import com.aizuda.easy.security.domain.Req;
import com.wt.admin.code.language.Tagging2100;
import com.wt.admin.config.aspect.annotation.LogAno;
import com.wt.admin.domain.dto.language.ClassTrainingDTO;
import com.wt.admin.domain.dto.language.ClassificationDTO;
import com.wt.admin.domain.dto.language.SentenceConfigDTO;
import com.wt.admin.domain.vo.language.ClassificationVO;
import com.wt.admin.domain.vo.language.ParseSentenceVO;
import com.wt.admin.domain.vo.language.SentenceConfigVO;
import com.wt.admin.domain.vo.sys.UserVO;
import com.wt.admin.service.language.LanguageProxyService;
import com.wt.admin.util.AssertUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import jakarta.annotation.Resource;
import java.util.List;


@RestController
@RequestMapping("classification")
public class ClassificationController {

    @Resource
    private LanguageProxyService languageProxyService;

    @LogAno(name = "添加分类")
    @PostMapping("add")
    public Rep<ClassificationVO> add(@RequestBody Req<ClassificationDTO, UserVO> req){
        return Rep.ok(languageProxyService.getClassificationService().add(req.getData()));
    }

    @LogAno(name = "分类列表")
    @PostMapping("list")
    public Rep<List<ClassificationVO>> list(@RequestBody Req<ClassificationDTO, UserVO> req){
        return Rep.ok(languageProxyService.getClassificationService().list(req.getData()));
    }

    @LogAno(name = "删除分类")
    @PostMapping("del")
    public Rep<ClassificationVO> del(@RequestBody Req<ClassificationDTO, UserVO> req){
        return Rep.ok(languageProxyService.getClassificationService().del(req.getData()));
    }

    @LogAno(name = "编辑分类")
    @PostMapping("edit")
    public Rep<ClassificationVO> edit(@RequestBody Req<ClassificationDTO, UserVO> req){
        return Rep.ok(languageProxyService.editClassAndSentence(req.getData()));
    }

    @LogAno(name = "训练样本")
    @PostMapping("classTraining")
    public Rep<ClassificationVO> classTraining(@RequestBody Req<ClassTrainingDTO, UserVO> req){
        AssertUtil.List.isEmpty(req.getData().getId(), Tagging2100.CODE_2105);
        languageProxyService.classTraining(req.getData(),req.getUser());
        return Rep.ok();
    }

    @LogAno(name = "测试样本")
    @PostMapping("testTraining")
    public Rep<ParseSentenceVO> testTraining(@RequestBody Req<String, UserVO> req){
        return Rep.ok(languageProxyService.testTraining(req.getData(),req.getUser()));
    }

    @LogAno(name = "查询配置")
    @PostMapping("findConfig")
    public Rep<SentenceConfigVO> findConfig(@RequestBody Req<SentenceConfigDTO, UserVO> req){
        req.getData().setTag("classification");
        return Rep.ok(languageProxyService.getSentenceConfigService().findConfig(req.getData(),req.getUser()));
    }

    @LogAno(name = "更新配置")
    @PostMapping("updateConfig")
    public Rep<SentenceConfigVO> updateConfig(@RequestBody Req<SentenceConfigDTO, UserVO> req){
        req.getData().setTag("classification");
        return Rep.ok(languageProxyService.getSentenceConfigService().updateConfig(req.getData(),req.getUser()));
    }

}
